﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using PCRemoteMobileVer;

namespace PCRemoteMoblieVer
{
    public partial class KeyboardSimulator : PhoneApplicationPage
    {
        public KeyboardSimulator()
        {
            InitializeComponent();
        }

        private void txtTextbox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                MainPage.SendCommand("KEYTYPE:" + txtTextbox.Text.Trim());
            }
        }

        private void keyControl_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_TAB");
        }

        private void keyAlt_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_BACK");
        }

        private void keyShift_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_DELETE");
        }

        private void keyTab_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_ENTER");
        }

        private void keyUp_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_UP");
        }

        private void keyLeft_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_LEFT");
        }

        private void keyRight_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_RIGHT");
        }

        private void keyDown_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_DOWN");
        }

        private void keyEnter_Tap(object sender, GestureEventArgs e)
        {
            MainPage.SendCommand("SENDKEY_ENTER");
        }

        private bool isKeyCtlPressed = false;
        private void keyComboCtl_Tap(object sender, GestureEventArgs e)
        {
            if (!isKeyCtlPressed)
            {
                keyComboCtl.Background = new SolidColorBrush(Colors.Yellow);
                isKeyCtlPressed = true;
            }
            else
            {
                keyComboCtl.Background = new SolidColorBrush(Colors.Green);
                isKeyCtlPressed = false;
            }
        }

        private bool isKeyAltPressed = false;
        private void keyComboAlt_Tap(object sender, GestureEventArgs e)
        {
            if (!isKeyAltPressed)
            {
                keyComboAlt.Background = new SolidColorBrush(Colors.Yellow);
                isKeyAltPressed = true;
            }
            else
            {
                keyComboAlt.Background = new SolidColorBrush(Colors.Green);
                isKeyAltPressed = false;
            }
        }

        private bool isKeyShiftPressed = false;
        private void keyComboShift_Tap(object sender, GestureEventArgs e)
        {
            if (!isKeyShiftPressed)
            {
                keyComboShift.Background = new SolidColorBrush(Colors.Yellow);
                isKeyShiftPressed = true;
            }
            else
            {
                keyComboShift.Background = new SolidColorBrush(Colors.Green);
                isKeyShiftPressed = false;
            }
        }

        private bool isKeyFnPressed = false;
        private void keyComboFn_Tap(object sender, GestureEventArgs e)
        {
            if (!isKeyFnPressed)
            {
                keyComboFn.Background = new SolidColorBrush(Colors.Yellow);
                isKeyFnPressed = true;
            }
            else
            {
                keyComboFn.Background = new SolidColorBrush(Colors.Green);
                isKeyFnPressed = false;
            }
        }
        
        private string GetControlKeys()
        {
            string controls = "";
            if (isKeyAltPressed)
            {
                controls += "_ALT";
            }
            if (isKeyCtlPressed)
            {
                controls += "_CTRL";
            }
            if (isKeyShiftPressed)
            {
                controls += "_SHIFT";
            }
            return controls;
        }
        private void keyF1_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F1";
            MainPage.SendCommand(results);
        }

        private void keyF2_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F2";
            MainPage.SendCommand(results);
        }

        private void keyF3_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F3";
            MainPage.SendCommand(results);
        }

        private void keyF4_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F4";
            MainPage.SendCommand(results);
        }

        private void keyF5_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F5";
            MainPage.SendCommand(results);
        }

        private void keyF6_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F6";
            MainPage.SendCommand(results);
        }

        private void keyF7_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F7";
            MainPage.SendCommand(results);
        }

        private void keyF8_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F8";
            MainPage.SendCommand(results);
        }

        private void keyF9_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F9";
            MainPage.SendCommand(results);
        }

        private void keyF10_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F10";
            MainPage.SendCommand(results);
        }

        private void keyF11_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F11";
            MainPage.SendCommand(results);
        }

        private void keyF12_Tap(object sender, GestureEventArgs e)
        {
            string results = "COMBOKEY" + GetControlKeys() + "_F12";
            MainPage.SendCommand(results);
        }

        private void keyControl_Click(object sender, RoutedEventArgs e)
        {

        }
        private void viewScreen(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }

    }
}